package com.hxzy.shop.controller.store;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.store.req.StoreListReq;
import com.hxzy.shop.common.dto.store.resp.SameCityDeliveryResp;
import com.hxzy.shop.common.dto.store.resp.StoreDetailResp;
import com.hxzy.shop.common.dto.store.resp.StoreListResp;
import com.hxzy.shop.common.dto.store.resp.StoreNumResp;
import com.hxzy.shop.constant.AuthConstant;
import com.hxzy.shop.entity.YxtCustomer;
import com.hxzy.shop.feign.merchant.MerchantFeign;
import com.hxzy.shop.feign.store.StoreFeign;
import com.hxzy.shop.utils.WebUtil;
import com.hxzy.shop.vo.ApiException;
import com.hxzy.shop.vo.Result;
import com.hxzy.shop.vo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 功能描述：门店管理
 *
 * @author tonneyyy
 */
@RestController
@Api(tags = "门店管理")
@RequestMapping("/storeManage")
public class StoreController {
    @Resource
    private StoreFeign storeFeign;

    @Resource
    private MerchantFeign merchantFeign;

    @ApiOperation(value = "门店列表", notes = "门店列表")
    @GetMapping(value = "/storeList")
    public Result<PageInfo<StoreListResp>> storeList(@Validated  StoreListReq req) {
       return this.storeFeign.storeList(req);
    }

    @ApiOperation(value = "门店数量", notes = "商户总店数量以及已开店数量")
    @GetMapping(value = "/storeNum")
    public Result<StoreNumResp> storeNum() {
        Result<StoreNumResp> storeNumRespResult = storeFeign.storeNum();

        //查询商家门店可以创建的总数量
        Result<Integer> integerResult = this.merchantFeign.selectStoreCount();
        if(integerResult.getCode()== ResultCode.SUCCESS.getCode()){
            storeNumRespResult.getData().setTotalStore(integerResult.getData());
        }else{
           throw new ApiException(500,integerResult.getMsg());
        }
        return storeNumRespResult;
    }

    @ApiOperation(value = "门店详情", notes = "门店详情")
    @GetMapping(value = "/storeDetail/{storeId}")
    public Result<StoreDetailResp> storeDetail(@PathVariable(value = "storeId") Long storeId){
      return this.storeFeign.storeDetail(storeId);
    }

    /**
     * 判断门店是否支持门店配送
     * @param storeId
     * @return
     */
    @ApiOperation(value = "判断门店是否支持门店配送", notes = "门店详情")
    @GetMapping(value = "/checkSameCityDelivery/{storeId}")
    public Result<SameCityDeliveryResp> checkSameCityDelivery(@PathVariable(value = "storeId") Long storeId){
        return this.storeFeign.checkSameCityDelivery(storeId);
    }

    /**
     * 获取客服地址列表
     */
    @ApiOperation(value = "获取客服地址列表")
    @GetMapping("/getTenantRedirectUrl")
    public Result<List<YxtCustomer>> getTenantRedirectUrl(){
        return  storeFeign.getTenantRedirectUrl() ;
    }
}
